import { Component, ChangeDetectorRef } from '@angular/core';
import { IonicPage, ViewController, NavParams } from 'ionic-angular';
import { EventProvider } from '../../providers/event/event';
/**
 * Generated class for the ProgressPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-progress',
  templateUrl: 'progress.html',
})
export class ProgressPage {

  //必须静态常量来传递
  private static thatPage: any;

  private progressValue: any;

  constructor(
    private changeDetectorRef: ChangeDetectorRef,
    public viewCtrl: ViewController,
    public navParams: NavParams,
    public event: EventProvider) {
    this.progressValue = "0";
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ProgressPage');
    ProgressPage.thatPage = this;
    //注册登录事件
    this.event.bindEvents(this.event.EVENT_PROGRESS_VALUE, this.eventPage);
  }

  /*界面销毁*/
  ionViewWillUnload() {
    this.event.unbindEvents(this.event.EVENT_PROGRESS_VALUE, this.eventPage);
  }

  /*侦听事件 */
  eventPage(val: any) {
    //执行登录检查
    if (val['status'] == 1) {
      ProgressPage.thatPage.progressValue = val['value'];
      ProgressPage.thatPage.changeDetectorRef.markForCheck();
      ProgressPage.thatPage.changeDetectorRef.detectChanges();
    } else {
      ProgressPage.thatPage.viewCtrl.dismiss();
    }
  }
}
